using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace MicroMsg.UI.UserContrl
{
	public class SetAccInfoSexAreaSigCtrl : BaseUserControl
	{
		public delegate void InfoOkCallBack(object sender, bool bIsInfoOk);
		private const int MAX_SIGN_LEN = 60;
		private string strProvince;
		private string strCity;
		private bool mBIsInitData;
		private string mStrSigOrigin = "";
		internal StackPanel LayoutRoot;
		internal TextBlock txtImportantTag1;
		internal ListPicker listPickerSex;
		internal TextBlock txtImportantTag2;
		internal Button btnSelectArea;
		internal TextBlock txtSelectArea;
		internal PhoneTextBox txtInputSignature;
		private bool _contentLoaded;
		public event SetAccInfoSexAreaSigCtrl.InfoOkCallBack mInfoOkCallBack;
		public SetAccInfoSexAreaSigCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.SetAccInfoSexAreaSigCtrl_Loaded));
		}
		private void SetAccInfoSexAreaSigCtrl_Loaded(object sender, RoutedEventArgs e)
		{
			if (!this.mBIsInitData)
			{
				this.mBIsInitData = true;
				if (this.isUnknownSex())
				{
					ItemsControl arg_48_0 = this.listPickerSex;
					List<string> list = new List<string>();
					list.Add(strings.Set_Person_Male);
					list.Add(strings.Set_Person_Female);
					list.Add("");
					arg_48_0.set_ItemsSource(list);
				}
				else
				{
					ItemsControl arg_72_0 = this.listPickerSex;
					List<string> list2 = new List<string>();
					list2.Add(strings.Set_Person_Male);
					list2.Add(strings.Set_Person_Female);
					arg_72_0.set_ItemsSource(list2);
				}
				this.refreshData();
				this.DataChangeProc();
				this.listPickerSex.SelectionChanged += new SelectionChangedEventHandler(this.SelectionChanged);
				this.txtInputSignature.set_Foreground(R.theme.COMMON_INPUTBOX_CONTENT_WORD_BRUSH);
			}
		}
		private void SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (this.mBIsInitData)
			{
				SelfPersonCard selfPersonCard = AccountMgr.getSelfPersonCard();
				if (selfPersonCard != null)
				{
					if (this.listPickerSex.SelectedIndex == 2)
					{
						selfPersonCard.nSex = 0;
					}
					else
					{
						selfPersonCard.nSex = ((this.listPickerSex.SelectedIndex == 0) ? 1 : 2);
					}
					AccountMgr.setSelfPersonCard(selfPersonCard);
					Contact contact = StorageMgr.contact.method_0(AccountMgr.curUserName);
					if (contact != null)
					{
						contact.nSex = selfPersonCard.nSex;
						StorageMgr.contact.modify(contact);
					}
				}
			}
		}
		private bool isUnknownSex()
		{
			SelfPersonCard selfPersonCard = AccountMgr.getSelfPersonCard();
			return selfPersonCard == null || (selfPersonCard.nSex != 1 && selfPersonCard.nSex != 2);
		}
		private void btnSelectArea_Click(object sender, RoutedEventArgs e)
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			if (basePage != null)
			{
				basePage.GoToPage("/Source/UI/Setting/SelectCountryPage.xaml", new object[]
				{
					new DelegateSelectArea(this.setAreaData)
				}, false);
			}
		}
		private void onSignatureChanged(object sender, TextChangedEventArgs e)
		{
			if (sender != null && sender is PhoneTextBox)
			{
				PhoneTextBox phoneTextBox = sender as PhoneTextBox;
				if (ToolFunction.getStrDisLen(phoneTextBox.get_Text()) <= 60)
				{
					this.mStrSigOrigin = phoneTextBox.get_Text();
					return;
				}
				if (this.mStrSigOrigin != null && this.mStrSigOrigin.get_Length() < phoneTextBox.get_Text().get_Length())
				{
					phoneTextBox.set_Text(this.mStrSigOrigin);
					phoneTextBox.set_SelectionStart(phoneTextBox.get_Text().get_Length());
				}
				this.mStrSigOrigin = phoneTextBox.get_Text();
			}
		}
		private void txtGotFofus(object sender, RoutedEventArgs e)
		{
			PhoneTextBox phoneTextBox = sender as PhoneTextBox;
			phoneTextBox.set_BorderBrush(R.theme.COMMON_BRUSH);
		}
		private void txtLostFofus(object sender, RoutedEventArgs e)
		{
			PhoneTextBox phoneTextBox = sender as PhoneTextBox;
			phoneTextBox.set_BorderBrush(null);
			ToolFunction.getStrDisLen(this.txtInputSignature.get_Text());
			if (phoneTextBox == this.txtInputSignature)
			{
				string text = this.txtInputSignature.get_Text();
				if (ToolFunction.getStrDisLen(text) > 60)
				{
					MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Set_Main_SignatureTooLong, false, "确定");
					mMMessageBox.OkBtn.add_Click(new RoutedEventHandler(this.dialog_OK_Btn_Click));
					return;
				}
				SelfPersonCard selfPersonCard = AccountMgr.getSelfPersonCard();
				if (selfPersonCard != null)
				{
					selfPersonCard.strSignature = this.trimToEmpty(text);
					AccountMgr.setSelfPersonCard(selfPersonCard);
					Contact contact = StorageMgr.contact.method_0(AccountMgr.curUserName);
					if (contact != null)
					{
						contact.strSignature = text;
						StorageMgr.contact.modify(contact);
					}
				}
			}
		}
		private void dialog_OK_Btn_Click(object sender, RoutedEventArgs e)
		{
			this.txtInputSignature.Focus();
		}
		private void inputTxt_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.get_Key() == 3)
			{
				base.Focus();
			}
		}
		private void updateAreaText(string strTempPro, string strTempCity)
		{
			string regionShow = ToolFunction.GetRegionShow(strTempPro, strTempCity);
			if (regionShow.Trim().get_Length() > 0)
			{
				this.txtSelectArea.set_Text(regionShow);
			}
		}
		private void setAreaData(string strTempPro, string strTempCity)
		{
			this.strProvince = strTempPro;
			this.strCity = strTempCity;
			this.updateAreaText(strTempPro, strTempCity);
			this.DataChangeProc();
		}
		public void refreshData()
		{
			SelfPersonCard selfPersonCard = AccountMgr.getSelfPersonCard();
			if (selfPersonCard != null)
			{
				if (this.isUnknownSex())
				{
					this.listPickerSex.SelectedIndex = 2;
				}
				else
				{
					this.listPickerSex.SelectedIndex = ((selfPersonCard.nSex == 1) ? 0 : 1);
				}
				this.txtInputSignature.set_Text(this.trimToEmpty(ToolFunction.SubStringDisLen(selfPersonCard.strSignature, 60)));
				this.strProvince = selfPersonCard.strProvince;
				this.strCity = selfPersonCard.strCity;
				this.updateAreaText(this.strProvince, this.strCity);
			}
		}
		public void saveData()
		{
		}
		private string trimToEmpty(string string_0)
		{
			if (string_0 != null)
			{
				return string_0.Trim().Replace("\n", "");
			}
			return "";
		}
		private void DataChangeProc()
		{
			bool bIsInfoOk = false;
			if ("" != this.trimToEmpty(this.txtSelectArea.get_Text()) && strings.Set_Person_SelectArea != this.trimToEmpty(this.txtSelectArea.get_Text()))
			{
				bIsInfoOk = true;
			}
			if (this.mInfoOkCallBack != null)
			{
				this.mInfoOkCallBack(this, bIsInfoOk);
			}
		}
		public void hideStars()
		{
			this.txtImportantTag1.set_Visibility(1);
			this.txtImportantTag2.set_Visibility(1);
		}
		public void showStars()
		{
			this.txtImportantTag1.set_Visibility(0);
			this.txtImportantTag2.set_Visibility(0);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/CommonUseControl/SetAccInfoSexAreaSigCtrl.xaml", 2));
			this.LayoutRoot = (StackPanel)base.FindName("LayoutRoot");
			this.txtImportantTag1 = (TextBlock)base.FindName("txtImportantTag1");
			this.listPickerSex = (ListPicker)base.FindName("listPickerSex");
			this.txtImportantTag2 = (TextBlock)base.FindName("txtImportantTag2");
			this.btnSelectArea = (Button)base.FindName("btnSelectArea");
			this.txtSelectArea = (TextBlock)base.FindName("txtSelectArea");
			this.txtInputSignature = (PhoneTextBox)base.FindName("txtInputSignature");
		}
	}
}
